package integral

import (
	"context"
	"enjoy-shop/formdata"
	"gitee.com/enjoy_5/integral-rpc/client"
	"gitee.com/enjoy_5/integral-rpc/proto/integral"
	"time"
)

func CreateIntegralRecord(ctx context.Context, in formdata.IntegralRecord) (*integral.IntegralRecordInfo, error) {
	info, err := client.CreateIntegralRecord(ctx, &integral.IntegralRecordInfo{
		IntegralNumber: in.IntegralNumber,
		//IntegralStatus: in.IntegralStatus,
		Describe: in.Describe,
		UserId:   in.UserId,
	})
	if err != nil {
		return nil, err
	}
	return info, err
}

func GetIntegralRecordList(ctx context.Context, in formdata.IntegralRecord) ([]*formdata.IntegralList, error) {
	//list, err := client.GetIntegralRecordList(ctx, in.UserId, in.IntegralStatus)
	//if err != nil {
	//	return nil, err
	//}

	//for _, v := range list {
	//	info = append(info, &formdata.IntegralList{
	//		ID:             v.ID,
	//		CreateTime:     time.Unix(v.CreateTime, 0),
	//		IntegralNumber: v.IntegralNumber,
	//		IntegralStatus: v.GetIntegralStatus(),
	//		Describe:       v.Describe,
	//		UserId:         v.UserId,
	//	})
	//}
	list, err := client.GetIntegralRecordList(ctx, in.UserId)
	if err != nil {
		return nil, err
	}
	var info []*formdata.IntegralList
	for _, v := range list {
		info = append(info, &formdata.IntegralList{
			ID:             v.ID,
			CreateTime:     time.Unix(v.CreateTime, 0),
			IntegralNumber: v.IntegralNumber,
			Describe:       v.Describe,
			UserId:         v.UserId,
		})
	}
	return info, nil
}

func GetIntegralInfo(ctx context.Context, in formdata.Integral) (*integral.IntegralInfo, error) {
	info, err := client.GetIntegralInfo(ctx, in.UserId)
	if err != nil {
		return nil, err
	}
	return info, err
}
